﻿#Region "IMPORTS"

Imports DAO

#End Region

Public Class FabricanteDao
    Inherits DAO(Of Fabricante)


#Region "CONSTRUTOR(S)"

    Public Sub New()
        MyBase.New()
    End Sub

#End Region

#Region "METODOS ABSTRATOS"

    Protected Overrides Sub ValidarInsert(modelo As Fabricante)

        Dim NHQL As String = "from Fabricante where Nome  = '" & modelo.Nome & "'"
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe um Fabricante com esse Nome")
        End If
    End Sub

    Protected Overrides Sub ValidarDelete(modelo As Fabricante)

    End Sub

    Protected Overrides Sub ValidarUpdate(ByVal modelo As Fabricante)

        Dim NHQL As String = "from Fabricante as c where c.Nome  = '" & modelo.Nome & "' AND c.FabricanteId != " & modelo.FabricanteId
        Dim list As IList = Me.Find(NHQL)
        If list.Count > 0 Then
            Throw New Exception("Já existe um Fabricante com esse Nome")
        End If

    End Sub

#End Region
End Class
